//---------------------------------------------------------------------------


#pragma hdrstop

#include "IniParam.h"
#include <IniFiles.hpp>
#include <Forms.hpp>

//---------------------------------------------------------------------------

#pragma package(smart_init)
#define cfg_file "c:\\param.ini"

static Param_Target Ini_Target;
static Bool    Ini_Param_Init()
{

}
static Bool    Ini_Param_Write(int key, DWORD  value)
{
    TIniFile *ini = new TIniFile(ChangeFileExt( Application->ExeName, ".INI" ));
    if(ini){
        AnsiString key_name;
        key_name.printf("key%d",(int)key);
        ini->WriteInteger("param",key_name,value);
        delete ini;
        return TRUE;
    }
    return FALSE;

}
static DWORD   Ini_Param_Read(int key,  DWORD  value)
{
    DWORD t = 0;
    TIniFile *ini = new TIniFile(ChangeFileExt( Application->ExeName, ".INI" ));
    if(ini){
        AnsiString key_name;
        key_name.printf("key%d",(int)key);
        t = ini->ReadInteger("param",key_name,value);
        delete ini;
        return t;
    }
    return value;
}

static Bool    Ini_WriteFloat(int key,   float  value)
{
    TIniFile *ini = new TIniFile(ChangeFileExt( Application->ExeName, ".INI" ));
    if(ini){
        AnsiString key_name;
        key_name.printf("key%d",(int)key);
        ini->WriteFloat("param",key_name,value);
        delete ini;
        return TRUE;
    }
    return FALSE;
}
static float   Ini_ReadFloat(int key,    float  value)
{
    float t = 0;
    TIniFile *ini = new TIniFile(ChangeFileExt( Application->ExeName, ".INI" ));
    if(ini){
        AnsiString key_name;
        key_name.printf("key%d",(int)key);
        t = ini->ReadFloat("param",key_name,value);
        delete ini;
        return t;
    }
    return value;
}
void Ini_Param_Target_Regiser()
{
    Ini_Target.Init  = Ini_Param_Init;
    Ini_Target.Write = Ini_Param_Write;
    Ini_Target.Read  = Ini_Param_Read;
    Ini_Target.ReadFloat   = Ini_ReadFloat;
    Ini_Target.WriteFloat  = Ini_WriteFloat;
    g_curTarget = &Ini_Target;
}
